package question4;


public class TestsVisiteurInfixe extends junit.framework.TestCase{
	private Memoire m;
	@SuppressWarnings("unused")
	private Variable x,x1;
	
	public void setUp(){
	  m  = new Memoire();
	  x  = new Variable(m,"x",3);
	  x1 = new Variable(m,"x1",5);
	}
	 
	 
	 public void testElementaire(){
	   Visiteur<String> vi = new VisiteurInfixe(m);
	   Expression expr = new Addition(new Constante(3), new Constante(2));
	   assertEquals("(3 + 2)", expr.accepter(vi));
	   expr = new Addition(expr, new Constante(2));
	   assertEquals("((3 + 2) + 2)",expr.accepter(vi));
	   expr = new Addition(expr, new Factoriel(x1));
	   assertEquals("{x=3, x1=5}",m.toString());
	   assertEquals("(((3 + 2) + 2) + x1!)", expr.accepter(vi));
	   expr = new Soustraction(expr, new Factoriel(x1));
     assertEquals("((((3 + 2) + 2) + x1!) - x1!)", expr.accepter(vi));
 	   expr = new Soustraction(expr, new Plus(new Factoriel(new Constante(5))));
 	   assertEquals("(((((3 + 2) + 2) + x1!) - x1!) - +(5!))", expr.accepter(vi));
	 }
}
